﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace Kooboo.Web.Areas.Commerce.Controllers
{
    using Kooboo.Commerce.AddIn;
    using Kooboo.Commerce;
    using Kooboo.IoC;
      [Authorize(Roles = "Administrator")]
    public class PromotionController : ControllerBase
    {
        public ActionResult Index()
        {
            var promotions = ObjectContainer.CreateInstances<IPromotion>()
                .OrderBy(i=>i.Name);

            return View(promotions);
        }

        public ActionResult Edit(string id)
        {
            var promotion = ObjectContainer.CreateInstances<IPromotion>()
                .FirstOrDefault(i => i.Name.ToLower() == id.ToLower());

            var promotionIndex = promotion.Views.Index();

            if (promotionIndex == null)
            {
                return this.RedirectToAction("Index");
            }
            else
            {
                return promotionIndex;
            }
        }

    }
}
